package co.yixiang.modules.shop.repository;

import co.yixiang.modules.shop.domain.YxStoreCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
* @author hupeng
* @date 2019-10-03
*/
public interface YxStoreCategoryRepository extends JpaRepository<YxStoreCategory, Integer>, JpaSpecificationExecutor {
    @Query(value = "select cate_name from yx_store_category where id = ?1",nativeQuery = true)
    String findNameById(Integer id);

    @Modifying
    @Query("update YxStoreCategory s set s.isDel = 1 where s.id =:id")
    void delCategory(Integer id);

    YxStoreCategory findByPid(Integer pid);
    /**
     * 通过级别编码查询商品分类
     * @param levelCode
     * @return
     */
    YxStoreCategory findByLevelCode(String levelCode);
    /**
     * 根据父类ID查询所有所属的子类
     * @param cateId
     * @return
     */
    @Query(value = "select a.id as id,b.id as pid from  yx_store_category a left join yx_store_category b on a.id = b.pid where  a.pid =?1 ",nativeQuery = true)
    List<Map<String,Integer>> findByChildCategory(Integer cateId);
}